Public Class FrmDocInfEdit
    Public DocID As Integer = 0
    Public frmDocument As Documents
    Dim dtDoc As New DsTempList.TBL_DOCDataTable
    Function validatedData() As Boolean
        If Me.txtAuthor.Text.Trim = "" Then
            MessageBox.Show("Invalid Author Name", "Virtual Desk", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Return False

        End If
        If Me.txtSubject.Text.Trim = "" Then
            MessageBox.Show("Invalid Document About", "Virtual Desk", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Return False

        End If
        If Me.txtKeyword.Text.Trim = "" Then
            MessageBox.Show("Invalid Documetn Keywords", "Virtual Desk", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Return False
        End If

        Return True

    End Function
    Function RefreshDocument() As Boolean
        If IsNothing(frmDocument.VDOCUMENTSBindingSource) = False Then
            frmDocument.VDOCUMENTSBindingSource.Filter = Nothing
        End If
        Dim STR() As String = frmDocument.TreeViewRepository.SelectedNode.Tag.ToString.Split("-")
        If STR(0) = "P" Then
            frmDocument.V_DOCUMENTSTableAdapter.FillByDOC_CAT_ID(frmDocument.DsTempList.V_DOCUMENTS, STR(1))
            frmDocument.dgDocuments.DataSource = frmDocument.VDOCUMENTSBindingSource
        End If
        If STR(0) = "C" Then
            frmDocument.V_DOCUMENTSTableAdapter.FillByDOC_SUB_CAT_ID(frmDocument.DsTempList.V_DOCUMENTS, STR(1))
            '' Me.TBL_DOC_COMMENTTableAdapter.FillByCOMMENT_DOC_ID(frmDocument.DsTempList.TBL_DOC_COMMENT, STR(1))
            frmDocument.dgDocuments.DataSource = frmDocument.VDOCUMENTSBindingSource
        End If
        frmDocument.TreeViewRepository.ContextMenuStrip = Nothing

    End Function
    Private Sub FrmDocInfEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DsTempList.TBL_DOC' table. You can move, or remove it, as needed.
        ''Me.TBL_DOCTableAdapter.Fill(Me.DsTempList.TBL_DOC)
        If DocID > 0 Then
            dtDoc = TBL_DOCTableAdapter.GetDataByDOC_ID(DocID)
            TBL_DOCTableAdapter.FillByDOC_ID(Me.DsTempList.TBL_DOC, DocID)
            Me.TBL_DOC_CATTableAdapter.FillByDOC_CAT_ACTIVE(Me.DsTempList.TBL_DOC_CAT, True)
            Me.TBL_DOC_SUB_CATTableAdapter.FillByCATEGOTY_ID(Me.DsTempList.TBL_DOC_SUB_CAT, dtDoc.Rows(0).Item("DOC_CAT_ID").ToString)
        Else
            MessageBox.Show("Invalid Document", "Virtual Desk", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Me.Close()
        End If
        DsTempList.AcceptChanges()



    End Sub
    Private Sub btn_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Save.Click
        If validatedData() = False Then
            Exit Sub
        End If
        Dim dowrow As DsTempList.TBL_DOCRow
        dowrow = Me.DsTempList.TBL_DOC.FindByDOC_ID(DocID)
        dowrow.DOC_AUTHOR = Me.txtAuthor.Text.Trim
        dowrow.DOC_CAT_ID = Me.cboRepository.SelectedValue
        dowrow.DOC_SUB_CAT_ID = Me.cboSubRepository.SelectedValue
        dowrow.DOC_SUBJECT = Me.txtSubject.Text.Trim
        dowrow.DOC_KEYWORDS = Me.txtKeyword.Text.Trim
        Try
            Me.TBLDOCBindingSource.EndEdit()
            Me.TBL_DOCTableAdapter.Update(Me.DsTempList.TBL_DOC)
            RefreshDocument()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        ''Me.DsTempList.TBL_DOC.Merge(Me.DsTempList.TBL_DOC)
        MessageBox.Show("Document Sucessfully Updated", "Virtual Desk", MessageBoxButtons.OK, MessageBoxIcon.Information)
        TBL_DOCTableAdapter.FillByDOC_ID(Me.DsTempList.TBL_DOC, DocID)
    End Sub
    Private Sub btn_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Close.Click
        Me.Close()
    End Sub

    Private Sub cboRepository_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboRepository.SelectedIndexChanged
        If IsNothing(Me.cboRepository.SelectedValue) = False Then
            Me.TBL_DOC_SUB_CATTableAdapter.FillByActive(Me.DsTempList.TBL_DOC_SUB_CAT, True, Me.cboRepository.SelectedValue)


        End If
    End Sub
End Class